﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TwoWheels.Order;

namespace TwoWheels.Account
{
    public class UserShoppingCart
    {
        
        public UserShoppingCart(int KlientID)
        {
            this.KlientID = KlientID;
            orderedProducts = new Dictionary<int, int>();
        }

        public void addToCart(int productID) 
        {
            if(orderedProducts.ContainsKey(productID))
            {
                orderedProducts[productID]++;
            } else
            {
                orderedProducts[productID] = 1;
            }
        }

        public void removeFromCart(int productID)
        {
            orderedProducts.Remove(productID);
        }

        public void removeOneItem(int productID)
        {
            if (orderedProducts.ContainsKey(productID))
            {
                if (orderedProducts[productID] == 1)
                    removeFromCart(productID);
                else if(orderedProducts[productID] > 1)
                    orderedProducts[productID]--;
            } 
        }

        public void makeOrder()
        {
            order = new Order.Order(orderedProducts,KlientID);
        }

        public Dictionary<int,int> Products
        {
            get { return orderedProducts; }
        }

        public Order.Order Order
        {
            get { return this.order; }
        }

        public int Id
        {
            get { return this.KlientID; }
        }


        private int KlientID;
        private Dictionary<int,int> orderedProducts; //slownik: produkt - ilosc
        private Order.Order order;
    }
}